package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.WorkOvertimeSpecDTO;
import com.eastfair.venueservice.dto.WorkOvertimeSpecPageQuery;
import com.eastfair.venueservice.dto.WorkOvertimeSpecSaveDTO;
import com.eastfair.venueservice.dto.WorkOvertimeSpecUpdateDTO;
import com.eastfair.venueservice.entity.WorkOvertimeSpec;
import com.eastfair.venueservice.service.WorkOvertimeSpecService;
import com.eastfair.venueservice.vo.WorkOvertimeSpecVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 加班规格
 * </p>
 *
 * @author dqq
 * @date 2023-05-05
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/workOvertimeSpec")
@Api(value = "WorkOvertimeSpec", tags = "加班规格")
@PreAuth(replace = "venueservice:workOvertimeSpec:")
public class WorkOvertimeSpecController extends SuperController<WorkOvertimeSpecService, Long, WorkOvertimeSpec, WorkOvertimeSpecPageQuery, WorkOvertimeSpecSaveDTO, WorkOvertimeSpecUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private WorkOvertimeSpecService workOvertimeSpecService;

    @Override
    public void handlerResult(IPage<WorkOvertimeSpec> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<WorkOvertimeSpec> workOvertimeSpecList = list
                .stream()
                .map((map) -> WorkOvertimeSpec.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(workOvertimeSpecList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<WorkOvertimeSpecPageQuery> params) {
        WorkOvertimeSpecPageQuery pageQuery = params.getModel();
    }

    /**
     * 加班规则ID查询规格列表VO.
     *
     * @param workOvertimeRuleId the work overtime rule id
     * @return the r
     */
    @GetMapping("/get/workOvertimeRuleId/{workOvertimeRuleId}")
    public R<List<WorkOvertimeSpecVO>> listByWorkOvertimeRuleId(@PathVariable("workOvertimeRuleId") Long workOvertimeRuleId) {
        log.info("listByWorkOvertimeRuleId - 加班规则ID查询规格列表VO, workOvertimeRuleId={}", workOvertimeRuleId);
        return R.successDef(workOvertimeSpecService.listVOByWorkOvertimeSpec(workOvertimeRuleId));
    }

    /**
     * 批量保存加班规格.
     *
     * @param list the list
     * @return the r
     */
    @PostMapping("/save/batch")
    public R<Boolean> saveBatch(@RequestBody List<WorkOvertimeSpecDTO> list) {
        log.info("saveBatch - 批量保存加班规格, list={}", list);
        return R.successDef(workOvertimeSpecService.saveBatch(list));
    }
}
